{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入工具包\n",
    "# add_water_marker_text_to_image 文字水印\n",
    "# add_water_marker_logo_to_image logo图片水印\n",
    "from watermarker import add_water_marker_text_to_image, add_water_marker_logo_to_image\n",
    "from img_utils import show_img"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 展示原始图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 原始图片路径\n",
    "src_image = \"./images/cat_dog.jpg\"\n",
    "# 查看原始图片\n",
    "show_img(src_image,\"原始图片\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 增加文字水印，并展示增加水印后的图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 增加水印后的图片路径\n",
    "out_image = './output/图片加文字水印.png'\n",
    "\"\"\"\n",
    "【使用参数说明】\n",
    "src_image: 原始图片路径\n",
    "out_image: 增加水印后的图片路径\n",
    "text: 增加水印文字内容\n",
    "\"\"\"\n",
    "add_water_marker_text_to_image(src_image=src_image, out_image=out_image,text='Python超人')\n",
    "\n",
    "show_img(out_image,\"文字水印\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 增加文字水印，使用更多的控制参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "【使用参数说明】\n",
    "src_image: 原始图片路径\n",
    "out_image: 增加水印后的图片路径\n",
    "text: 增加水印文字内容\n",
    "alpha: 透明度 0 - 1，默认：0.8\n",
    "rotate: 旋转角度，默认：-45度\n",
    "font_file: 字体文件，默认：微软雅黑（默认 C:\\Windows\\Fonts\\下的字体，如果不存在，则使用微软雅黑）\n",
    "font_size: 字号大小，默认：50\n",
    "h_density: 文字水平疏密程度，默认：1，越大越密\n",
    "v_density: 文字垂直疏密程度，默认：1，越大越密\n",
    "\"\"\"\n",
    "add_water_marker_text_to_image(\n",
    "    src_image=src_image, out_image=out_image, text='Python超人',\n",
    "    alpha=0.5, rotate=0, font_file=\"msyh.ttc\",\n",
    "    font_size=40, h_density=2, v_density=2)\n",
    "\n",
    "show_img(out_image,\"文字水印\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 增加Logo图片水印，并展示增加水印后的图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_image = './output/图片加Logo水印.png'\n",
    "logo_image = './images/python_icon.png'\n",
    "\"\"\"\n",
    "【使用参数说明】\n",
    "src_image: 原始图片路径\n",
    "out_image: 增加Logo水印后的图片保存路径\n",
    "logo_image: Logo图片路径\n",
    "alpha: 透明度 0 - 1，默认：0.8\n",
    "rotate: 旋转角度，默认：0\n",
    "logo_scale: Logo图片缩放，1为原尺寸，默认为 0.5\n",
    "position: Logo水印的位置，比如：(10,200)，并支持如下九种布局方式：\n",
    "          topleft、topmiddle、topright、middleleft、middlecenter、\n",
    "          middleright、bottomleft、bottommiddle、bottomright\n",
    "\"\"\"\n",
    "add_water_marker_logo_to_image(\n",
    "    src_image=src_image,\n",
    "    out_image=out_image,\n",
    "    logo_image=logo_image,\n",
    "    alpha=1,\n",
    "    rotate=0,\n",
    "    logo_scale=0.5,\n",
    "    position=(10, 200)\n",
    ")\n",
    "show_img(out_image, \"Logo水印\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课程建议"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font color=red>如果大家有什么好的建议，或者功能无法满足您的要求，欢迎留言！</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
